package com.jishuo.base.util;

/**
 * 通用工具类
 */
public class CommonUtil {

    /**
     * 根据id字串，返回long数组
     * @param ids id字符串
     * @param regex 分隔符
     * @return
     */
    public static long[] getIdsLong(String ids, String regex) {
        if (StringUtil.isEmpty(ids)) return new long[]{};
        String[] s = ids.split(regex);
        long[] l = new long[s.length];
        int n = 0;
        try {
            for (int i=0;i<s.length;i++) {
                if (StringUtil.isNotEmpty(s[i])) {
                    l[n] = Long.parseLong(s[i]);
                    n++;
                }
            }
        } catch (Exception e) {
            return new long[]{};
        }
        if (n == s.length) return l;
        long[] ret = new long[n];
        System.arraycopy(l, 0, ret, 0, n);
        return ret;
    }

    /**
     * 根据id字串，返回long数组
     * @param ids id字符串，逗号隔开
     * @return
     */
    public static long[] getIdsLong(String ids) {
        return getIdsLong(ids, ",");
    }

    public static String getIncomeway(Object incomeway){
        if(incomeway==null){
            return "";
        }
        if("1".equals(incomeway.toString())){
            return "是";
        }else{
            return "否";
        }
    }

    public static String getPayway(Object payway){
        if(payway==null){
            return "";
        }
        if("1".equals(payway.toString())){
            return "现金";
        }else if("2".equals(payway.toString())){
            return "支票";
        }else if("3".equals(payway.toString())){
            return "转账";
        }else{
            return "其他";
        }
    }

    public static String getIshand(Object ishand){
        if(ishand==null){
            return "";
        }
        if("0".equals(ishand.toString())){
            return "电子票";
        }else{
            return "手工票";
        }
    }

    public static String getIssend(Object issend){
        if(issend==null){
            return "";
        }
        if("2".equals(issend.toString())){
            return "已传输";
        }else{
            return "未传输";
        }
    }

    /**
     * 检查库中支付日期是否与输入一致
     * @param oldDate 库中日期
     * @param newDate 输入日期
     * @return
     */
    public static boolean checkPaybankdt(String oldDate, String newDate) {
        if (StringUtil.isEmpty(oldDate)) return true;
        return oldDate.substring(0, 10).equals(newDate.substring(0, 10));
    }
}
